package zhklappoint.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import zhklappoint.annotation.IgnoreAuth;
import zhklappoint.enums.ENUM_SUCESS;
import zhklappoint.util.ResponseBean;
import zhklappoint.util.Tools;

@Controller
@CrossOrigin
public class UploadImgController {
	
	 //编辑预约系统的公司或者活动的背景图片
    @RequestMapping(value = "/addIndexImage",method = RequestMethod.POST,consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ResponseBody
    public String addIndexImage(@RequestPart("file") MultipartFile file) {
//    	System.out.println("file===="+file);
    	 String imgUrl = Tools.getImageUrl(file,"backimg","indexpage",0,"");
//    	 System.out.println("imgUrl：："+imgUrl);
//    	 String imgUrl="shop_93bc504622674fe4b0a5b941e00e9ea0.jpg";
    	 String allimgUrl=Tools.splitString(imgUrl, "backimg","indexpage",0);
    	 Map<String,String> mss = new HashMap<String,String>();
    	 mss.put("imgUrl", imgUrl);
    	 mss.put("allUrl", allimgUrl);
        if(imgUrl=="0") {
        	return ResponseBean.of(null, ENUM_SUCESS.FAILED.value,"单张图片大小不能超过3M");
        }
        return ResponseBean.of(mss, ENUM_SUCESS.SUCESS.value,"成功上传了图片");
    }
    //首页获取商户列表
	@RequestMapping(value="/checkheartReload",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String checkheartReload() {
		return "success";
	}
}
